<?php
//this model is using for users....
class Task_model extends Model{
	
	function Task_model()
	{
		parent::Model();
		$this->load->database();
	}
	
  
  
 	public function task_list()
	{
		$this->CI =& get_instance();
		
		$this->db->select('* FROM tbl_task');
		$this->CI->flexigrid->build_query();
		
		//Get contents
		$return['records'] = $this->db->get();
		
		//Build count query
		$this->db->select('count(task_id) as record_count from tbl_task ');
		$this->CI->flexigrid->build_query(FALSE);
		$record_count = $this->db->get();
		$row = $record_count->row();
		
		//Get Record Count
		$return['record_count'] = $row->record_count;
	
		//Return all
		return $return;
	}
	
	function task_count()
	{
		$result = $this->db->query("select * from tbl_task ");
		return $result->num_rows();
	}	
	
	function list_task($num,$limitnum)
	{
		$result = $this->db->query("select * from tbl_task order by task_desc ASC limit ".$num." , ".$limitnum);
		return $result;
	}
	
  public function display_task()
  {
        $this->CI =& get_instance();
      
        $this->db->select('* from tbl_task ');
        $this->CI->flexigrid->build_query();
        
        //Get contents
        $return['records'] = $this->db->get();
        
        //Build count query
        $this->db->select('count(task_id) as record_count from tbl_task');
        $this->CI->flexigrid->build_query(FALSE);
        $record_count = $this->db->get();
        $row = $record_count->row();
        
        //Get Record Count
        $return['record_count'] = $row->record_count;
      
        //Return all
        return $return;
  }
  
	function insert_task()
	{
		
    		$check = $this->db->query("select * from tbl_task where task_desc like '".$_POST['task_name']."'");
    		
    		if($check->num_rows() == 0)
    		{
    			$this->db->set('task_desc', $_POST['task_name']);
    			$this->db->insert('tbl_task');	
    		}
    		else
    		{
    			redirect("task/duplicate_task");
    		}
	}
	
	function task_edit($id)
	{
		$result = $this->db->query("select * from tbl_task where task_id =".$id);
		return $result;
	}
	
	function edit_save()
	{
		$data = array(
               'task_desc' => $_POST['task_name'],
		            );

	$this->db->where('task_id', $_POST['id']);
	$this->db->update('tbl_task', $data);
	}
	
}
